class Employee < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me ,:first_name ,:middle_name ,:last_name, :is_manager , :is_active, :is_admin,:sign_in_count,:role_name
	validates_presence_of :first_name
	validates_presence_of :last_name
	validates_presence_of :email
	validates_uniqueness_of :email

  
  has_many :authentications,:dependent => :destroy
  has_many :clients
  has_many :cases


   def active_for_authentication?
    super && account_active?
   end

  def account_active?
    if self.is_admin?
      return true
    elsif self.is_active
      return true
    else
      return false
    end
  end

  def full_name
    return [self.first_name, self.middle_name, self.last_name].join(' ')
  end

  def get_client
    if self.is_manager || self.is_admin
      return Client.all
    else
      return Client.where("employee_id = #{self.id}")
    end
  end

end
